﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************

Imports System.ComponentModel
Imports System.Text

''' <summary>
''' Content class
''' </summary>
''' <remarks></remarks>
Public Class Content
    Inherits GGE.BaseItem
#Region "Enum"
    Public Enum enumViewType
        Home
        Canvas
        Preview
        Profile
    End Enum
#End Region
#Region "Fields"
    Private _viewType As String = String.Empty
    Private _description As String = String.Empty
    Private _Name As String = String.Empty
    Private _content As String = String.Empty
#End Region
#Region "Propertys"
    <BrowsableAttribute(False), CategoryAttribute("Misc"), Description("The Main Code")> _
    Public Property Content() As String
        Get
            Return _content
        End Get
        Set(ByVal value As String)
            _content = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Description")> _
    Public Property Description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Name of the code")> _
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
            Me.SetDirty()
        End Set
    End Property
    <TypeConverter(GetType(Views)), CategoryAttribute("Misc"), Description("View Type Home,Canvas,Profile")> _
    Public Property ViewType() As String
        Get
            Return _viewType
        End Get
        Set(ByVal value As String)
            _viewType = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False)> _
    Public Overrides ReadOnly Property ObjectName() As String
        Get
            Return Me.Name
        End Get
    End Property
#End Region
#Region "Constructor"
    Public Sub New()

    End Sub
    Public Sub New(ByVal Name As String, ByVal Description As String, ByVal ViewType As enumViewType)
        Me.Name = Name
        Me.Description = Description
        Me.ViewType = ViewType
    End Sub
    Public Sub New(ByVal ViewType As String)
        Me.ViewType = ViewType
    End Sub
#End Region
#Region "Methods"
    Public Overrides Function BuildXml() As String
        Dim sb As StringBuilder = New StringBuilder
        If Me.ViewType = "" Then
            sb.AppendLine("<Content type=""html""><![CDATA[")
        Else
            sb.AppendLine("<Content type=""html"" view=""" & Me.ViewType.ToString & """><![CDATA[")
        End If

        sb.AppendLine(Me.Content)
        sb.AppendLine("]]></Content>")
        Return sb.ToString
    End Function
#End Region
End Class


''' <summary>
''' Content collection
''' </summary>
''' <remarks></remarks>
Public Class ViewCollection
    Inherits GGE.BaseCollection(Of Content)
#Region "Methods"
    Public Shadows Sub Add(ByVal Title As String, ByVal Description As String, ByVal ViewType As Content.enumViewType)
        MyBase.Add(New Content(Title, Description, ViewType))
    End Sub
    Public Shadows Sub Add(ByVal ViewType As Content.enumViewType)
        MyBase.Add(New Content(ViewType))
    End Sub
    Public Shadows Sub Add(ByVal oContent As Content)
        MyBase.Add(oContent)
    End Sub
    Public Shadows Function BuildXml(Optional ByVal BuildView As String = "") As String
        Dim sb As StringBuilder = New StringBuilder
        For Each Tobj As Content In Me
            If BuildView = "" Then
                Dim strbuf As String = Tobj.BuildXml
                If Not String.IsNullOrEmpty(strbuf) Then
                    sb.AppendLine(Tobj.BuildXml)
                End If
            ElseIf BuildView.ToUpper = Tobj.ViewType.ToUpper Then
                'Build only this view
                Dim strbuf As String = Tobj.BuildXml
                If Not String.IsNullOrEmpty(strbuf) Then
                    sb.AppendLine(Tobj.BuildXml)
                End If
                Return sb.ToString
            End If
        Next
        Return sb.ToString
    End Function
#End Region
#Region "Properties"
    Public Overrides ReadOnly Property ObjectName() As String
        Get
            Return "Content"
        End Get
    End Property
#End Region
End Class